package com.cskaoyan.controller.wx;

import com.cskaoyan.Utils.MyUtils;
import com.cskaoyan.bean.goods.Goods;
import com.cskaoyan.bean.userbean.Footprint;
import com.cskaoyan.mapper.goodsmapper.GoodsMapper;
import com.cskaoyan.mapper.usermapper.FootprintMapper;
import com.cskaoyan.service.wx.WxGoodsService;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.mallvo.BrandVo;
import com.cskaoyan.vo.wx.*;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

/**
 * @author hsp
 * @date 2021/5/13 20:01
 */
@RestController
@RequestMapping("wx/goods")
public class WxGoodsController {
    @Autowired
    WxGoodsService wxGoodsService;
    @Autowired
    GoodsMapper goodsMapper;
    @Autowired
    FootprintMapper footprintMapper;




    @RequestMapping("count")
    @ResponseBody
    public BaseRespVo goodsCount() {

        Integer goodsCount = wxGoodsService.getGoodsCount();


        return BaseRespVo.ok(new WxGoodsCountVo(goodsCount));
    }

    @RequestMapping("category")
    public BaseRespVo category(Integer id) {

        WxCategoryVo wxCategoryVo = wxGoodsService.getCategoryMessage(id);
        return BaseRespVo.ok(wxCategoryVo);
    }

    @RequestMapping("list")
    public BaseRespVo getGoodsList(String keyword,String sort,String order,Integer categoryId, Integer brandId, Integer page, Integer size) {

        WxgoodListVo wxgoodListVo = null;
        if (categoryId != null)
            wxgoodListVo = wxGoodsService.getGoodsListByCategoryId(categoryId, page, size);
        if (brandId!=null)
            wxgoodListVo = wxGoodsService.getGoodsListByBrandId(brandId, page, size);
        if (keyword!=null)
            wxgoodListVo = wxGoodsService.getGoodsListByKeyword(keyword, page, size,sort,order);

        return BaseRespVo.ok(wxgoodListVo);

    }

    @RequestMapping("detail")
    public BaseRespVo detail(Integer id){

        WxGoodsDetailVo wxGoodsDetailVo = wxGoodsService.getDetail(id);

        return BaseRespVo.ok(wxGoodsDetailVo );
    }

    @RequestMapping("related")
    public BaseRespVo related(Integer id){

        WxGoodsRelatedVo wxGoodsRelatedVo = wxGoodsService.getRelated(id);

        return BaseRespVo.ok(wxGoodsRelatedVo);
    }
}
